class Solution {
public:
    bool isSubStructure(TreeNode* A, TreeNode* B) {
        if(A==NULL || B==NULL) return false;
    	return recur(A,B) || isSubStructure(A->left,B) || isSubStructure(A->right,B) ;
    }
private:
	bool recur(TreeNode* A, TreeNode* B){
		if(B == NULL) return true;
		else if(A == NULL) return false;
        bool left = 0;
        bool right = 0;
		if(A->val == B->val){
			left = recur(A->left,B->left);
			right = recur(A->right,B->right);
		}
        return left && right;
	}
};